package com.spzx.order.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.rabbit.constants.MqConst;
import com.spzx.common.rabbit.service.RabbitService;
import com.spzx.order.configure.DelayedMqConfig;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * projectName: spzx-parent
 *
 * @author: 王宝贵
 * time: 2024/10/17 18:36 周四
 * description: 发送消息的调用层（生产者）
 */
@Slf4j
@RestController
@RequestMapping("/mq")
@Tag(name = "新MQ测试")
public class MqController001  extends BaseController {

    @Autowired
    private RabbitService rabbitService;

    @Operation(summary = "发送确认消息")
    @GetMapping("/sendConfirmMessage")
    public AjaxResult sendConfirmMessage(){
        rabbitService.sendMessage(MqConst.EXCHANGE_TEST,MqConst.ROUTING_CONFIRM,"hello ,confirm");
        return success();
    }

    @Operation(summary = "发送延迟消息：基于延迟插件")
    @GetMapping("/sendDelayMsg")
    public AjaxResult sendDelayMsg() {
        //调用工具方法发送延迟消息
        int delayTime = 10; //希望延迟10秒再被消费。
        rabbitService.sendDelayMessage(DelayedMqConfig.exchange_delay, DelayedMqConfig.routing_delay, "我是延迟消息", delayTime);
        //延迟消息发送到交换机，立马执行回退回调。10秒后转发队列时，routingKey错的，也不再执行回退了。
        //rabbitService.sendDelayMessage(DelayedMqConfig.exchange_delay, "xxxx", "我是延迟消息", delayTime);

        return success();
    }

}